/**
 * <p>图形控件</p>
 * xtype = cceafchart

 * @module Ext-ux-cceaf-control
 * @class cceaf.control.Chart
 * @extends Ext.chart.Chart
 * @since 1.0
 */
Ext.define('cceaf.control.sjjh.JkChart',{
	extend: 'Ext.chart.Chart', 
    alias: 'widget.cceafchart',

    /**
	 * 构造函数
	 *
	 * @method constructor
	 * @param {attribute} config 配置项
	 */
	constructor: function(config){
		config = config || {};
		
		cceaf.control.sjjh.JkChart.superclass.constructor.apply(this, arguments);
	},
	
	/**
	 * store的model名称
	 *
     * @property model 
     * @type String
     * @default 'ChartModel'
     */
	model: 'ChartModel',
	
	/**
	 * 横坐标标题
	 *
     * @property xTitle 
     * @type String
     * @default null
     */
	xTitle: null,
	
	/**
	 * 纵坐标标题
	 *
     * @property yTitle 
     * @type String
     * @default null
     */
	yTitle: null,
	
	/**
	 * 名称字段
	 *
     * @property nameFields 
     * @type String
     * @default null
     */
	nameFields: null,
	
	/**
	 * 数据字段
	 *
     * @property dataFields 
     * @type String
     * @default null
     */
	dataFields: null,
	
	/**
	 * 获取数据的action，对应struts action
	 *
     * @property action 
     * @type String
     * @default null
     */
	action: null,
	
	
	initComponent : function(){
		var config = this;
		
		var model = 'ChartModel';
		if (config.model) {
			model = config.model;
		}
		
		var xTitle,yTitle;
		if (config.xTitle) {
			xTitle = config.xTitle;
		} 
		if (config.yTitle) {
			yTitle = config.yTitle;
		} 
		
		var nameFields,dataFields;
		if (config.nameFields) {
			nameFields = config.nameFields;
		} else {
			cceaf.util.ExtHelper.showInfoDialog('请设置nameFields');
			return;
		}
		if (config.dataFields) {
			dataFields = config.dataFields;
		} else {
			cceaf.util.ExtHelper.showInfoDialog('请设置dataFields');
			return;
		}
		
		//定义数据源
	    var ds;
	    if (config.store) {
	    	ds = config.store;
	    } else {
	    	ds = new Ext.data.Store({
		    	proxy: {
		    		type: 'ajax',
		    		url: config.action,
		    		reader: {
						type: 'json',
						root: 'data',
						totalProperty: 'totalCount',
						messageProperty: 'message'
					}
				},
		        /*listeners: {
		        	'load': function(){
		        		var jr = ds.getProxy().getReader();
		        		var message = jr.jsonData.message;
		        		var url = jr.jsonData.url;
		        		cceaf.util.ExtHelper.showInfoDialog(message,url);
		        	},
		        	'loadexception': function(){
		        		var jr = ds.getProxy().getReader();
		        		if(jr.jsonData){
			        		var message = jr.jsonData.message;
			        		var url = jr.jsonData.url;
			        		cceaf.util.ExtHelper.showErrorDialog(message,url);
		        		}
		        		else{
		        			cceaf.util.ExtHelper.showErrorDialog("返回无效的JSONDATA数据");
		        		}
		        	}
		        },*/
		        
		        autoDestroy: true,  
		    	//pageSize: szpshang.Global.PAGE_SIZE,
		    	model: model
		    });
	    	
	    	
	    	/*ds = new Ext.data.JsonStore({
			fields:['type', 'proportion'],
			data: [
				{type :'内存', proportion : 10},
				{type :'CPU', proportion : 40},
				{type :'C盘', proportion : 30},
				{type :'D盘', proportion : 20}
			]
		});*/
        
        }
        
        
		Ext.applyIf(this, {
			store: ds,
	        style: 'background:#fff',
            animate:true,
            shadow: true,
            legend: {
              position: 'bottom'  
            },
            axes: [{
                type: 'Numeric',
                position: 'left',
                fields: dataFields,
                label: {
                    renderer: Ext.util.Format.numberRenderer('0,0')
                },
                title: yTitle,
                grid: true,
                minimum: 0,
                maximum : 100//数轴最大值
            }, {
                type: 'Category',
                position: 'bottom',
                fields: nameFields,
                title: xTitle
            }],
            
            series: [{
                type: 'column',
                axis: 'left',
                highlight: true,
                
                tips: {
	            	trackMouse: true,
	                width: 140,
	                height: 28,
	                renderer: function(storeitem, item) {
	                	this.setTitle(storeitem.get('type')+':'+storeitem.get('proportion')+'%');
	                }
	            },
	            
                label: {
                  	display: 'outside',
                  	'text-anchor': 'middle',
                    field: dataFields,
                    renderer: Ext.util.Format.numberRenderer('0'),
                    orientation: 'horizontal',
                    color: '#333',
                    font : '18px "Lucida Grande"',//字体
                    renderer : function(v){//自定义标签渲染函数
							return v + '%';
					}
                },
                //title : ['CPU','内存','硬盘'],//配置图例字段说明
                xField: nameFields,
                yField: dataFields
            }]
            
		});
		
		cceaf.control.sjjh.JkChart.superclass.initComponent.call(this);
    },

    initEvents: function() {
    	cceaf.control.sjjh.JkChart.superclass.initEvents.call(this);
    }
    
});